package com.kinggm.service.observer.impl;

import com.kinggm.service.observer.DisplayElement;

import java.util.Observable;
import java.util.Observer;

public class CurrentConditionsDisplayNew implements Observer, DisplayElement {

    public CurrentConditionsDisplayNew(Observable observable) {
        this.observable = observable;
        observable.addObserver(this);
    }

    Observable observable;
    private float temperature;
    private float humidity;
    private float pressure;

    @Override
    public void display() {
        System.out.println("CurrentConditionsDisplayNew  \n 温度: " + temperature + "℃" + "湿度：" + humidity + "%" + "气压：" + pressure + "hPa");
    }


    @Override
    public void update(Observable observable, Object o) {
        if(observable instanceof WeatherDataNew){
            WeatherDataNew weatherDataNew = (WeatherDataNew) observable;
            this.temperature = weatherDataNew.getTemperature();
            this.humidity = weatherDataNew.getHumidity();
            this.pressure = weatherDataNew.getPressure();
            display();
        }
    }


}
